#include "StdAfx.h"
#include "SimpleCriticalSection.h"

namespace RoomFW {

SimpleCriticalSection::SimpleCriticalSection(void)
{
	::InitializeCriticalSection(&cs_);
}

SimpleCriticalSection::~SimpleCriticalSection(void)
{
	::DeleteCriticalSection(&cs_);
}

void SimpleCriticalSection::enter(void)
{
	::EnterCriticalSection(&cs_);
}

bool SimpleCriticalSection::tryEnter(void)
{
	return ::TryEnterCriticalSection(&cs_);
}

void SimpleCriticalSection::leave(void)
{
	::LeaveCriticalSection(&cs_);
}

CriticalSectionGuard::CriticalSectionGuard(SimpleCriticalSection& cs) :
	cs_(cs)
{
	cs_.enter();
}

CriticalSectionGuard::~CriticalSectionGuard(void)
{
	cs_.leave();
}

}
